#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: relation.py 
@version:
@time: 2022/01/06 
"""
from TapException.TM import DataFlowBuildError
from TapUtil.logfunc.logger import logger


class MapTable:
    """
    迁移任务 sink 配置
    """

    def __init__(self, **kwargs):
        self.prefix = kwargs.get('prefix', '')
        self.suffix = kwargs.get('suffix', '')
        self.dropType = kwargs.get('dropType', 'no_drop')
        self.tableNameTransform = kwargs.get('tableNameTransform', '')
        self.fieldsNameTransform = kwargs.get('fieldsNameTransform', '')


class Association:
    def __init__(self, **kwargs):
        self.joinType = kwargs.get('joinType', 'upsert')
        self.joinPath = kwargs.get('joinPath', '')
        self.manyOneUpsert = kwargs.get('manyOneUpsert', False)
        # joinKeys: [(key, key)]
        self.joinKeys = kwargs.get('joinKeys', [])
        self.arrayUniqueKey = kwargs.get('arrayUniqueKey', '')
        self.isArray = kwargs.get('isArray', False)
        self.associationType = kwargs.get('associationType', '')
        if not self.joinKeys:
            logger.fatal('association need joinKeys')
            raise DataFlowBuildError
        if kwargs.get('redisKeyPrefix', False):
            self.redisKeyPrefix = kwargs.get('redisKeyPrefix')
